var express = require('express');
var router = express.Router();


var multer = require("multer");
var storage = multer.diskStorage({
    destination:function(req,file,cb){
        cb(null,"./public/images/file")
    },
    filename:function(req,file,cb){
        if(!req.pics){
            req.pics = [];
        }
        var time = Date.now();
        console.log(file)
        var suffix = file.originalname.split(".")[file.originalname.split(".").length-1];
        var fn = time+"."+suffix;
        req.pics.push(fn);
        cb(null,fn);
    }
});
var upload = multer({
    storage:storage
});

/* 上传文件 */
router.post('/file.do',upload.single("pic"), function(req, res) {
// router.post('/file.do',upload.array("pic"), function(req, res) {
  console.log(req.body);
  console.log(req.pics)
  res.json({err:0,msg:'负重前行'});
});




module.exports = router;
